#ifndef SPIDERNODE_H_
#define SPIDERNODE_H_

#include <iostream>
#include <string>
#include <uv.h>
#include "define.h"
#include "spidermessage.h"
class Master;

class SpiderNode
{
private:
    uint32_t m_ip;
    Master *m_master;
    uv_tcp_t m_connect;
    uv_timer_t m_spiderTimer;
    uint64_t m_interval;
    uint64_t m_lastRecvTick;
    bool m_isInit;

public:
    uint32_t m_ipaddr;
    std::string m_uuid;
    uint32_t m_sendLen;
    char m_sendBuf[TCP_BUFF_SIZE];
    uint32_t m_recvLen;
    char m_recvBuf[TCP_BUFF_SIZE];

public:
    SpiderNode()
    {
        m_ip = 0;
        m_interval = 0;
        m_lastRecvTick = 0;
        m_isInit = false;
        m_uuid = "";
        m_recvLen = 0;
    }
    ~SpiderNode() {}

    bool Init(Master *master, uv_stream_t *pServer, uint32_t interval);
    void HandReaddata(ssize_t nread);

    bool DoRegister(MessageRegister *msg);

    void OnSpiderNodeCheck();

    void Close(bool cache);

    void SendMessageRegisterResp();
    void SendHeartbeatResp(MessageHeartbeat *resp);
    void SendTask(char *task, uint16_t taskLen);
};

#endif